/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cashmate.struts;


import com.cashmate.hibernate.dao.LoanverificationDAO;
import com.cashmate.hibernate.pojo.Loanverification;
import com.opensymphony.xwork2.ActionSupport;
import java.util.ArrayList;
import java.util.List;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;

/**
 *
 * @author Lee
 */
public class GetLoanapps_CM extends ActionSupport {

    //private BorrowerDAO bord = (BorrowerDAO) ServletActionContext.getServletContext().getAttribute("borrowerDAO");
    private LoanverificationDAO lvd = (LoanverificationDAO) ServletActionContext.getServletContext().getAttribute("loanverificationDAO");
    private String[] lacmList;
    private List<String> lacmList1;

    public String[] getLacmList() {
        return lacmList;
    }

    @Action(value = "/get-la-cm", results = {
        @Result(name = "input", location = "/loanapplication.jsp"),
        @Result(name = "success", location = "/loanapplication.jsp"),
        @Result(name = "error", location = "/loanapplication.jsp")
    })
    @Override
    public String execute() {
//            System.out.println("yes");
            lacmList1 = new ArrayList<String>();
            List<Loanverification> llacm = null;
            List<Loanverification> llacmnocm = null;

            try {
            llacm = lvd.getAll();
        } catch (Exception e) {
            e.printStackTrace();
        }

        if (llacm != null) {
            llacmnocm = new ArrayList<Loanverification>();
            for (int i = 0; i < llacm.size(); i++) {
                if (!llacm.get(i).getWithcm().equals("y")) {
                    llacmnocm.add(llacm.get(i));
//                    System.out.println(llacm.get(i).getLoanverificationid());
                }
            }
        }
        
        if (!llacmnocm.isEmpty()) {
            for (int i = 0; i < llacmnocm.size(); i++) {
                String id = llacmnocm.get(i).getDocumentno();
                String borcode = llacmnocm.get(i).getBorrowers().getBorrowercode();
                String name = llacmnocm.get(i).getBorrowers().getCompletename();

                String info = id + " " + borcode + " " + name;
//                System.out.println(info);
                lacmList1.add(info);
            }

            lacmList = lacmList1.toArray(new String[lacmList1.size()]);
//            System.out.println(lacmList);
        }
        return SUCCESS;

    }
}
